/*
 * Copyright (C) 2012 SeekDeepWithin.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.seekdeepwithin.Data;

/**
 * User: Jonathan Montiverdi
 * Date: Oct 5, 2012
 *
 * Helper utility for HTML.
 */
public final class Html
{
   public static String Newline = System.getProperty ("line.separator");

   /**
    * Gets the HTML for the start of a page.
    * @param pageTitle Title of page being displayed.
    * @return HTML data.
    */
   public static String getPageStart (String styles)
   {
      StringBuilder css = new StringBuilder ();
      css.append ("<!DOCTYPE html>")
              .append ("<html>")
              .append (Newline)
              .append ("<head>")
              .append (Newline)
              .append ("<title>SeekDeepWithin</title>")
              .append (Newline)
              .append ("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">")
              .append (Newline)
              .append (styles)
              .append (Newline)
              .append ("<script type=\"text/javascript\">")
              .append (Newline)
              .append ("function scrollTo (hash) {location.hash = \"#\" + hash;}")
              .append (Newline)
              .append ("if (document.addEventListener){")
              .append (Newline)
              .append ("element.addEventListener('contextmenu', function(e) {")
              .append (Newline)
              .append ("e.preventDefault ();")
              .append (Newline)
              .append ("}, false);}")
              .append (Newline)
              .append ("</script>")
              .append (Newline);
      return css.toString ();
   }

   /**
    * Gets the HTML for the start of the body a page.
    * @return HTML data.
    */
   public static String getBodyStart ()
   {
      StringBuilder css = new StringBuilder ();
      css.append ("</head>")
              .append (Newline)
              .append ("<body>")
              .append (Newline);
      return css.toString ();
   }

   /**
    * Gets the HTML for the end of a page.
    * @return HTML data.
    */
   public static String getPageEnd ()
   {
      StringBuilder css = new StringBuilder ();
      css.append ("</body>")
              .append (Newline)
              .append ("</html>");
      return css.toString ();
   }

   /**
    * Gets the CSS data for a page.
    * @return CSS data.
    */
   public static String getCss ()
   {
      StringBuilder css = new StringBuilder ();
      /*Button Gradients from: http://www.webdesignerwall.com/demo/css-buttons.html*/
      css.append ("<style type=\"text/css\">")
              .append (Newline)
              .append ("body {font-family:\"Lucida Grande\",Verdana,Helvetica,Arial,sans-serif;}")
              //.append ("a:link {color:#1C2B61;}")
              //.append ("a:visited {color:#1C2B61;}")
              //.append ("a:hover {color:#1C2B61;}")
              //.append ("a:active {color:#1C2B61;}")
              .append (".alnleft {text-align: left;}")
              .append (".footer ul {list-style-type: none;}")
              .append (".footer th {padding: 7px;}")
              .append (".footer td {padding: 5px;border-left: 1px solid #000;}")
              .append (".definition {color: #2E629D;cursor: help;}")
              .append (".header {font-weight: bold;text-align: center;}")
              .append ("div.tsk {font-size:smaller;text-align:center;}")
              .append ("dl.tsk {padding: 0;font-size:smaller;margin:0px;}")
              .append (".sectionBreak {text-align: center;font-size: X-large;font-weight: bold;}")
              .append (".glossaryHeader {font-size: large;font-weight: bold;color: #317eac;}")
              .append (".sectionHeader {font-size: large;font-weight: bold;color: #317eac;text-align: center}")
              .append (".chapHeader {font-weight: bold;text-align: center;}")
              .append (".chapFooter {padding: 40px;padding-bottom: 10px;text-align: center;}")
              .append (".tsk dt {position: relative;left: 0;top: 1.1em;width: 5em;font-weight: bold;font-size:smaller;}")
              .append (".tsk dd {border-left: 1px solid #000;margin: 0 0 0 6em;padding: 0 0 .5em .5em;font-size:smaller;}")
              .append (Newline)
              .append ("</style>")
              .append (Newline);
      return css.toString ();
   }

   /**
    * Strips all the HTML from the given text.
    * @param text Text to strip HTML from.
    * @return Text with no HTML.
    */
   public static String StripHtml (String text)
   {
      return text.replaceAll ("<(.*?)>", "").replaceAll ("\\(\\d+\\)", "");
   }
}
